package com.controller.task;

import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.common.template.FreeMarkerTemplateUtils;
import com.service.task.ExcelService;

import freemarker.template.Template;
import freemarker.template.TemplateException;

@Controller
public class ExcelController {

	@Autowired
	ExcelService excelService;

	@RequestMapping("/SurpviseManage/export")
	public void exportExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
		response.reset();
		request.setCharacterEncoding("utf-8");
		response.setHeader("Content-type", "text/html;charset=UTF-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/x-msdownload");
		response.setHeader("Content-Disposition", "attachment; filename=\"test.xlsx\"");

		String templateName = "task.ftl";
		Template template = FreeMarkerTemplateUtils.getTemplate(templateName);
		Writer writer = response.getWriter();
		Map<String, Object> dataMap = new HashMap<String, Object>();
		try {
			template.process(dataMap, writer);
		} catch (TemplateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		writer.flush();
		writer.close();
	}
}
